#include("/front/teacher/_layout.html")
#@layout()
#define layoutImportcss()
    <link rel="stylesheet" type="text/css" href="/front/css/timeline.css">
#end
#define layoutHead()
<title>相册 - 班级首页</title>
#end
#define layoutHome()

	<div class="page-content photos-page-content infinite-scroll-content"> 
	<div class="navbar">
		<div class="navbar-inner toolbstyle">
			<div class="left">
				<a href="javascript:history.back()" class="link back">
					<i class="icon icon-back"></i>
				</a>
			</div>
			<div class="title" id="navbar_title"></div>
			<div class="right"></div>
		</div>
	</div>                 
		<!--<div class="banner"><img src="/front/img/bjxc1.jpg"></div>-->

		<div class="timeline">
			
		</div>
		
		<!--加载gif图-->
		<div class="preloader infinite-scroll-preloader"></div>
	</div>
#end
#define layoutImportjs()
#end
#define layoutScript()
<script type="text/javascript">
	var stu_id = getUrlParam('stuid');
	
	var cur_pageNo = 1;
	var cur_pageTotals = 1;
	// Loading flag
	var loading = false;
	var allimgs = "";
	var img_idx = 0;
	var pageSize = 5;
	var myDate = new Date();
	var start_date;
	var end_date;
	
	if (!isBlank(stu_id) && stu_id>0){ 
		$$('.banner img').attr('src', '/front/img/bbxc1.jpg'); 
		$$('.navbar a.back').attr('href', "javascript:window.location.href='/front/teacher/html/students'");
	}

	function bindEvent(){
		$$('img.col-33-img').off('click', showPhotosPanel);
		$$('img.col-33-img').on('click', showPhotosPanel);
	}
	function showPhotosPanel(){
		var arryimg = trim(allimgs,';').split(';')
		var idx = $$(this).attr('img-idx');
		var myPhotoBrowser = app.photoBrowser.create({
			photos : arryimg,
			theme: 'dark'
		});
		if (idx > 0) myPhotoBrowser.activeIndex = idx;
		myPhotoBrowser.open();
	}
	
	// 监听滚动事件
	$$('.infinite-scroll-content').on('infinite', function () {
	    // Exit, if loading in progress
		if (loading) return;

		// Set loading flag
		loading = true;
	
	    getPage(cur_pageNo+1);
	});
	
	function getPage(pageNo){
		var idy = (0 - pageSize);
		if (pageNo == 1){
			start_date = formatDate(myDate.toString(), 'yyyy-MM-dd 23:59:59');
		} else {
			start_date = end_date;
		}
		end_date = formatDate(StringToDate(start_date).DateAdd('d', idy).toString(), 'yyyy-MM-dd 23:59:59');	
		var surl = "/front/teacher/album/getAlbum?pageNo=" + pageNo + "&pageSize=" + global_pagesize+ "&typeid=1&start_date="+start_date+"&end_date="+end_date + "&stuid=" + stu_id;
		
		sendPost(surl, null, function(res){
			console.log(res);
			cur_pageNo = pageNo;
			
			if (pageNo == 1){
				$$('div.timeline').html('');
				allimgs = "";
				img_idx = 0;
				
				var stitle = '班级相册';
				if (isJsonProps(res, 'student_rd')){
					stitle = res.student_rd.student_name + '的相册';
				}
				$$('#navbar_title').html(stitle);
			}
			
			
			if (res.pageData.list.length>0){
				
				loading = false;
				
				cur_pageTotals = res.pageData.totalPage;
				
				for (var i = 0; i < res.pageData.list.length; i++) {
					var jdata = res.pageData.list[i];
					getTemplateHtml(jdata);
				}
				
				bindEvent();
			}
			if (cur_pageNo>=cur_pageTotals){
				app.infiniteScroll.destroy('.infinite-scroll-content');
				$$('.infinite-scroll-preloader').html('没有更多数据了！')
												.addClass('loaded')
												.removeClass('preloader')
												.removeClass('infinite-scroll-preloader');
				
			}
			
		});
	}
	
	function getTemplateHtml(jdata){
		//console.log(jdata);
		var shtml = '';
		var imghtml = "";
		var strdate = jdata.add_time.split(' ')[0]
		var arrydate = strdate.split('-');

		var divdate = $$('div[date="'+strdate+'"] .photos-row');
		//console.log(divdate);
		if (divdate.length<=0){
			shtml = '<div class="timeline-item" date="'+strdate+'"><div class="timeline-item-date"><b>'+arrydate[2]+'</b>/<small>'+arrydate[1]+'月</small></div><div class="timeline-item-divider"></div><div class="timeline-item-content" style="width:100%;"><div class="photos-row section-right-row"></div></div></div>';
			
			$$('div.timeline').append(shtml);
			
			divdate = $$('div[date="'+strdate+'"] .photos-row');
			if (divdate.length<=0){
				console.log('div[date="'+strdate+'"] photos-row ::: not finded');
				return;
			}
		}
		
		// 图片
		if (!isBlank(jdata.picese_imgs)){
			var imgs = trim(jdata.picese_imgs, ';');			
			var arryimg = imgs.split(';');
			allimgs += imgs + ";";
			var j_num = 0;
			for(var j=0; j<arryimg.length; j++){
				imghtml += '<div class="col-33"><img class="col-33-img" src="'+getZoomFileUrl(arryimg[j])+'" data-id="'+jdata.picese_id+'" img-idx="'+img_idx+'" style="width:100px"></div>';
				img_idx++;
				j_num++;
			}
			divdate.append(imghtml);
		}
	}
	
	getPage(1);
</script>
#end
